//
//  AYSSmallDetailModel.m
//  AiYingShiProject
//
//  Created by lanou on 15/11/3.
//  Copyright (c) 2015年 李晓理. All rights reserved.
//

#import "AYSSmallDetailModel.h"
#import "UIView+WLFrame.h"
#import "UIView_extra.h"
#import <UIImageView+WebCache.h>
@implementation AYSSmallDetailModel
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        
        //内容背景
        self.blurbackImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _blurbackImgView.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.blurbackImgView];
        self.blurbackImgView.userInteractionEnabled = YES;
        self.equalH = _blurbackImgView.height / 10;
       
        //播放按钮的图片
        self.playImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_blurbackImgView.frame.size.width / 2 - 30, _blurbackImgView.frame.size.height / 2 - 30, 60, 60)];
        self.playImageView.image = [UIImage imageNamed:@"播放2"];
        [self addSubview:self.playImageView];
        
        //标题
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kEdge, 0, _blurbackImgView.width - 2 * kEdge, self.equalH)];
        [self setUpLabel:_titleLabel];
        _titleLabel.font = [UIFont systemFontOfSize:18];
        
        //分类和时间
        self.classLabel = [[UILabel alloc]initWithFrame:CGRectMake(kEdge, _titleLabel.bottom, SCREEN_WIDTH - 2 * kEdge, self.equalH / 3 * 2)];
        [self setUpLabel:_classLabel];
        [self.blurbackImgView addSubview:self.classLabel];
        
        //内容简介
        self.contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(kEdge, _classLabel.bottom + self.equalH, SCREEN_WIDTH - 2 * kEdge, 3.5 * self.equalH)];
        [self setUpLabel:_contentLabel];
        
        //收藏按钮
        self.collectButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        //分享按钮
        self.shareButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.collectButton.frame = CGRectMake(kEdge * 4, _blurbackImgView.height - 60, kIconWidth , kIconHeight);
        self.shareButton.frame = CGRectMake(SCREEN_WIDTH / 2 + kEdge * 3, _collectButton.top, kIconWidth, kIconHeight);
        [self.collectButton setBackgroundImage:[UIImage imageNamed:@"收藏2"] forState:(UIControlStateNormal)];
        [self.collectButton setBackgroundImage:[UIImage imageNamed:@"收藏"] forState:(UIControlStateSelected)];
        [_collectButton addTarget:self action:@selector(clickCollectButton:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.shareButton setBackgroundImage:[UIImage imageNamed:@"分享2"] forState:(UIControlStateNormal)];
        [_blurbackImgView addSubview:_collectButton];
        [_blurbackImgView addSubview:_shareButton];
        //加入收藏
        self.collectLabel = [[UILabel alloc]initWithFrame:CGRectMake(kEdge * 4 + kIconWidth, _collectButton.top, (SCREEN_WIDTH - _collectButton.right), kLabelHeight)];
        [self setUpLabel:_collectLabel];
        //分享数量
        self.shareLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + kIconWidth + kEdge * 3, _collectButton.top, _collectLabel.width, kLabelHeight)];
        [self setUpLabel:_shareLabel];
        
    }
    return self;
}

- (void)clickCollectButton:(UIButton *)button
{
    button.selected = !button.selected;
}

#pragma mark-----设置Label的属性
- (void)setUpLabel:(UILabel *)label
{
    //文本颜色
    label.textColor = [UIColor whiteColor];
    //文本居左
    label.textAlignment = NSTextAlignmentLeft;
    //文本字体和大小
    label.font = [UIFont systemFontOfSize:14];
    //文本全部输出
    label.numberOfLines = 0;
    [self.blurbackImgView addSubview:label];
}

- (void)changeContentValueWithModel:(AYSSmallListModel *)model
{
    //模糊图片
    [self.blurbackImgView sd_setImageWithURL:[NSURL URLWithString:model.coverBlurred]];
    //标题
    self.titleLabel.text = model.title;
    //类别和时间
    self.classLabel.text =  [NSString stringWithFormat:@"#%@ / %02ld'%02ld\"",model.category, [model.duration integerValue] / 60, [model.duration integerValue] % 60];
    //内容简介
    self.contentLabel.text = model.videoListDescription;
    CGRect frame = [self.contentLabel.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 2 * kEdge, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName] context:nil];
    self.contentLabel.frame = CGRectMake(kEdge, _classLabel.bottom + self.equalH / 2, SCREEN_WIDTH - 2 * kEdge, frame.size.height);
    //点赞数
    self.collectLabel.text = [NSString stringWithFormat:@"%ld", model.collectionCount];
    //分享
    self.shareLabel.text = [NSString stringWithFormat:@"%ld", model.shareCount];
}

@end
